<?php
session_start();
    if(!isset($_SESSION['pwd']) || empty($_SESSION['pwd']))
    {
        header("Location: login.php"); 
        exit;
    }
if(isset($_REQUEST['onsub'])){
    if( $_REQUEST['onsub']=='ok')
    {
          //require_once dirname(__FILE__) . '/../includes/common.inc.php';
          require_once dirname(__FILE__) . '/../includes/data.cfg.php';  
          require_once dirname(__FILE__) . '/../includes/pdoorm.inc.php';
        
          $export_name = BRANCH.$_REQUEST['begin_date'].'--'.$_REQUEST['end_date'].'wpeOrder';
          header("Content-type:application/vnd.ms-excel");
          header("Content-Disposition:attachment;filename=$export_name.xls");
        
        
          //require_once dirname(__FILE__) . '/includes/pdoorm.inc.php';
          
          
          $sql="SELECT m.customerId,m.type,m.photoname,m.videoname,LEFT(FROM_UNIXTIME(m.date),10) as wdate,LEFT(FROM_UNIXTIME(c.createdDate),10) AS cdate FROM ns_v1myorder AS m ,ns_v1customer AS c WHERE m.customerId=c.e_oid  
                AND (m.type LIKE'Wedding%'  OR m.type LIKE'Prewedding%' OR m.type LIKE'Engagement%') 
                AND LEFT(FROM_UNIXTIME(c.createdDate),10) BETWEEN '".$_REQUEST['begin_date']."' AND '".$_REQUEST['end_date']."'
                ORDER BY  c.createdDate DESC ";
          $dataarr = getall($sql,1);
          echo"<table border='1'><tr>";
          echo " <td colspan='5' height='30px' align='center'><h3>".$export_name."</h3></td></tr><tr height='27' style='font-weight:bold;'>";
          echo   "<td>Customer NO</td>";
          echo   "<td>Created Date</td>";
          echo   "<td>Photoname</td>";
          echo   "<td>Videoname</td>";
          echo   "<td>Type</td>";
          echo  "</tr>";  
        
          if(is_array($dataarr))
          {
            foreach ($dataarr as $dr)
            {
               echo" <tr>";        
               echo   "<td>".$dr['customerId']."</td>";
               echo   "<td>".$dr['cdate']."</td>";
               echo   "<td>".$dr['photoname']."</td>";
               echo   "<td>".$dr['videoname']."</td>";
               echo   "<td>".$dr['type']."</td>";
               echo  "</tr>";      
            }
          }
          echo"</table>";
          die;
    }

}


if(isset($_REQUEST['wonsub'])){
    if( $_REQUEST['wonsub']=='ok')
    {
          //require_once dirname(__FILE__) . '/../includes/common.inc.php';
          require_once dirname(__FILE__) . '/../includes/data.cfg.php';  
          require_once dirname(__FILE__) . '/../includes/pdoorm.inc.php';
        
          $export_name = BRANCH.$_REQUEST['begin_date'].'--'.$_REQUEST['end_date'].'wOrder';
          header("Content-type:application/vnd.ms-excel");
          header("Content-Disposition:attachment;filename=$export_name.xls");
        
        
          //require_once dirname(__FILE__) . '/includes/pdoorm.inc.php';
          
          
          $sql="SELECT m.customerId,m.type,m.photoname,m.videoname,LEFT(FROM_UNIXTIME(m.date),10) as wdate,LEFT(FROM_UNIXTIME(c.createdDate),10) AS cdate FROM ns_v1myorder AS m ,ns_v1customer AS c WHERE m.customerId=c.e_oid  
                AND (m.type LIKE'Wedding%') 
                AND LEFT(FROM_UNIXTIME(m.date),10) BETWEEN '".$_REQUEST['begin_date']."' AND '".$_REQUEST['end_date']."'
                ORDER BY  m.date DESC ";
          $dataarr = getall($sql,1);
          echo"<table border='1'><tr>";
          echo " <td colspan='5' height='30px' align='center'><h3>".$export_name."</h3></td></tr><tr height='27' style='font-weight:bold;'>";
          echo   "<td>Customer NO</td>";
          echo   "<td>wedding Date</td>";
          echo   "<td>Photoname</td>";
          echo   "<td>Videoname</td>";
          echo   "<td>Type</td>";
          echo  "</tr>";  
        
          if(is_array($dataarr))
          {
            foreach ($dataarr as $dr)
            {
               echo" <tr>";        
               echo   "<td>".$dr['customerId']."</td>";
               echo   "<td>".$dr['wdate']."</td>";
               echo   "<td>".$dr['photoname']."</td>";
               echo   "<td>".$dr['videoname']."</td>";
               echo   "<td>".$dr['type']."</td>";
               echo  "</tr>";      
            }
          }
          echo"</table>";
          die;
    }

}

if(isset($_REQUEST['peonsub'])){
    if( $_REQUEST['peonsub']=='ok')
    {
          //require_once dirname(__FILE__) . '/../includes/common.inc.php';
          require_once dirname(__FILE__) . '/../includes/data.cfg.php';  
          require_once dirname(__FILE__) . '/../includes/pdoorm.inc.php';
        
          $export_name = BRANCH.$_REQUEST['begin_date'].'--'.$_REQUEST['end_date'].'peOrder';
          header("Content-type:application/vnd.ms-excel");
          header("Content-Disposition:attachment;filename=$export_name.xls");
        
        
          //require_once dirname(__FILE__) . '/includes/pdoorm.inc.php';
          
          
          $sql="SELECT m.customerId,m.type,m.photoname,m.videoname,LEFT(FROM_UNIXTIME(m.date),10) as wdate,LEFT(FROM_UNIXTIME(c.createdDate),10) AS cdate FROM ns_v1myorder AS m ,ns_v1customer AS c WHERE m.customerId=c.e_oid  
                AND (m.type LIKE'Prewedding%' OR m.type LIKE'Engagement%') 
                AND LEFT(FROM_UNIXTIME(m.date),10) BETWEEN '".$_REQUEST['begin_date']."' AND '".$_REQUEST['end_date']."'
                ORDER BY  m.date DESC ";
          $dataarr = getall($sql,1);
          echo"<table border='1'><tr>";
          echo " <td colspan='5' height='30px' align='center'><h3>".$export_name."</h3></td></tr><tr height='27' style='font-weight:bold;'>";
          echo   "<td>Customer NO</td>";
          echo   "<td>wedding Date</td>";
          echo   "<td>Photoname</td>";
          echo   "<td>Videoname</td>";
          echo   "<td>Type</td>";
          echo  "</tr>";  
        
          if(is_array($dataarr))
          {
            foreach ($dataarr as $dr)
            {
               echo" <tr>";        
               echo   "<td>".$dr['customerId']."</td>";
               echo   "<td>".$dr['wdate']."</td>";
               echo   "<td>".$dr['photoname']."</td>";
               echo   "<td>".$dr['videoname']."</td>";
               echo   "<td>".$dr['type']."</td>";
               echo  "</tr>";      
            }
          }
          echo"</table>";
          die;
    }

}

include 'header.php';
?>
 <br>
 <div>
    <fieldset>
    <legend>W/P/E Order</legend>
      <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
        <label><span style="color:red;font-weight:bolder;">Date format:2010-01-01</span></label><br>
        <label>C/Date<input type="text" name ="begin_date" id="begin_date"></label><label> TO <input type="text" name ="end_date" id="end_date"></label>
        <label><input type="hidden" name="onsub" id="onsub"  value="ok">
        <input type="submit" value="download"></label>
      </form>
    </fieldset>
 </div>
 
  <div>
    <fieldset>
    <legend>W Order</legend>
      <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
        <label><span style="color:red;font-weight:bolder;">Date format:2010-01-01</span></label><br>
        <label>W/Date<input type="text" name ="begin_date" id="begin_date"></label><label> TO <input type="text" name ="end_date" id="end_date"></label>
        <label><input type="hidden" name="wonsub" id="wonsub"  value="ok">
        <input type="submit" value="download"></label>
      </form>
    </fieldset>
 </div>
 
  <div>
    <fieldset>
    <legend>P/E Order</legend>
      <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
        <label><span style="color:red;font-weight:bolder;">Date format:2010-01-01</span></label><br>
        <label>W/Date<input type="text" name ="begin_date" id="begin_date"></label><label> TO <input type="text" name ="end_date" id="end_date"></label>
        <label><input type="hidden" name="peonsub" id="peonsub"  value="ok">
        <input type="submit" value="download"></label>
      </form>
    </fieldset>
 </div>
  
 
 
 
 
 
 
 
 
 
 
 
 
 